package com.springboot.util;

import java.util.*;

import org.springframework.util.StringUtils;

import com.springboot.bean.Came;

public class CameHelper {

	private static List<Came> list = null;

	private static List<Came> initList() {
		if (list != null && !list.isEmpty())
			return list;
		list = new ArrayList<>(128);

		list.add(Came.getCame("loc", "BL", "Bus Lane"));
		list.add(Came.getCame("loc", "BLG", "Under Permament Building"));
		list.add(Came.getCame("loc", "CR", "Cross Road"));
		list.add(Came.getCame("loc", "DIF", "Difficult Access Area"));
		list.add(Came.getCame("loc", "EX", "Expressway"));
		list.add(Came.getCame("loc", "FLD", "Fields"));
		list.add(Came.getCame("loc", "FWY", "Footway"));
		list.add(Came.getCame("loc", "RD", "Road"));
		list.add(Came.getCame("loc", "PD", "Other Pedestrian Area"));
		list.add(Came.getCame("loc", "WWY", "Under a Waterway"));
		list.add(Came.getCame("loc", "Z", "Other"));

		list.add(Came.getCame("cat", "Z", "Z"));

		list.add(Came.getCame("sha", "A", "Arched with Flat Bottom"));
		list.add(Came.getCame("sha", "B", "Barrel e.g. Beer Barrel Shape"));
		list.add(Came.getCame("sha", "C", "Circular"));
		list.add(Came.getCame("sha", "E", "Egg Shape"));
		list.add(Came.getCame("sha", "H", "Horseshoe"));
		list.add(Came.getCame("sha", "O", "Oval"));
		list.add(Came.getCame("sha", "K", "Kerb Block"));
		list.add(Came.getCame("sha", "R", "Rectangular"));
		list.add(Came.getCame("sha", "S", "Square"));
		list.add(Came.getCame("sha", "T", "Trapezoidal"));
		list.add(Came.getCame("sha", "U", "U-shaped with Flat Top"));
		list.add(Came.getCame("sha", "Z", "Other"));

		list.add(Came.getCame("mat", "AC", "Asbestos Cement"));
		list.add(Came.getCame("mat", "BL", "Bitumen Lining"));
		list.add(Came.getCame("mat", "BR", "Brick"));
		list.add(Came.getCame("mat", "CI", "Cast Iron"));
		list.add(Came.getCame("mat", "CL", "Cement Mortar Lining"));
		list.add(Came.getCame("mat", "CO", "Concrete"));
		list.add(Came.getCame("mat", "CS", "Concrete Segments"));
		list.add(Came.getCame("mat", "DI", "Ductile Iron"));
		list.add(Came.getCame("mat", "EP", "Epoxy"));
		list.add(Came.getCame("mat", "FC", "Fibre Cement"));
		list.add(Came.getCame("mat", "FRP", "Fibre Reinforced Plastics"));
		list.add(Came.getCame("mat", "GI", "Galvanised Iron"));
		list.add(Came.getCame("mat", "MAC", "Masonry in Regular Courses"));
		list.add(Came.getCame("mat", "MAR", "Masonry in Randomly Coursed"));
		list.add(Came.getCame("mat", "PVC", "Polyvinyl Chloride"));
		list.add(Came.getCame("mat", "PE", "Polyethylene"));
		list.add(Came.getCame("mat", "PF", "Pitch Fibre"));
		list.add(Came.getCame("mat", "PP", "Polypropylene"));
		list.add(Came.getCame("mat", "PS", "Polyester"));
		list.add(Came.getCame("mat", "RC", "Reinforced Concrete"));
		list.add(Came.getCame("mat", "SPC", "Sprayed Concrete"));
		list.add(Came.getCame("mat", "ST", "Steel"));
		list.add(Came.getCame("mat", "VC", "Vitrified Clay"));
		list.add(Came.getCame("mat", "X", "Unidentified Material"));
		list.add(Came.getCame("mat", "XI", "Unidentified Type of Iron or Steel"));
		list.add(Came.getCame("mat", "XP", "Unidentified Type of Plastics"));
		list.add(Came.getCame("mat", "Z", "Other"));

		list.add(Came.getCame("lin", "CF", "Close Fit Lining"));
		list.add(Came.getCame("lin", "CIP", "Cured In Place Lining"));
		list.add(Came.getCame("lin", "CP", "Lining With Continuous Pipes"));
		list.add(Came.getCame("lin", "DP", "Lining With Discrete Pipes"));
		list.add(Came.getCame("lin", "M", "Lining Inserted During Manufacture"));
		list.add(Came.getCame("lin", "N", "No Lining"));
		list.add(Came.getCame("lin", "SEG", "Segmental Linings"));
		list.add(Came.getCame("lin", "SP", "Sprayed Lining"));
		list.add(Came.getCame("lin", "SW", "Spirally Wound Lining"));
		list.add(Came.getCame("lin", "Z", "Other"));

		list.add(Came.getCame("use", "F", "Foul"));
		list.add(Came.getCame("use", "S", "Surface water"));
		list.add(Came.getCame("use", "C", "Combined"));
		list.add(Came.getCame("use", "T", "Trade effluent"));
		list.add(Came.getCame("use", "W", "Watercourse"));
		list.add(Came.getCame("use", "O", "Others"));
		list.add(Came.getCame("use", "U", "Unknown"));

		list.add(Came.getCame("dir", "U", "Upstream"));
		list.add(Came.getCame("dir", "D", "Downstream"));

		list.add(Came.getCame("wea", "1", "Dry"));
		list.add(Came.getCame("wea", "2", "Heavy Rain"));
		list.add(Came.getCame("wea", "3", "Light Rain"));
		list.add(Came.getCame("wea", "4", "Showers"));

		return list;
	}

	public static String getCameName(String text, String model) {
		List<Came> list = initList();
		Optional<Came> optional = list.stream().filter(came -> Objects.equals(came.getModel(), model) && Objects.equals(came.getText(), text)).findFirst();
		if (optional.isPresent())
			return optional.get().getName();
		return "";
	}

	public static String getCameText(String name, String model) {
		List<Came> list = initList();
		Optional<Came> optional = list.stream().filter(came -> Objects.equals(came.getModel(), model) && Objects.equals(came.getName(), name)).findFirst();
		if (optional.isPresent())
			return optional.get().getText();
		return "";
	}

}
